/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AMMercaderia.java
 *
 * Created on 10/11/2010, 18:53:38
 */

package vista;

import modelo.CategoriaProducto;
import modelo.MarcaProducto;
import modelo.MovimientoStock;
import modelo.Proveedor;
import modelo.TipoMovimiento;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import negocio.ExcepcionValidacion;
import negocio.FabricaNegocio;
import negocio.ServiciosNegocio;

/**
 *
 * @author Aguero
 */
 class AMMercaderia extends javax.swing.JDialog {

    ControladorProductos mercaderias;
    private ServiciosNegocio serviciosCategorias;
    private ServiciosNegocio serviciosMarcas;
    private ServiciosNegocio serviciosProveedores;
    private Mercaderias padre;
    private boolean modificar;
    private Long id;
    private ArrayList<Proveedor> listaProv;
    

    /** Creates new form AMMercaderia */
    public AMMercaderia(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

     public AMMercaderia(javax.swing.JDialog parent, boolean modal) {
        super(parent, modal);
        mercaderias = new ControladorMercaderias(FabricaNegocio.getServicioMercaderias());
        serviciosCategorias = FabricaNegocio.getServicioCategorias();
        serviciosMarcas = FabricaNegocio.getServicioMarcas();
        serviciosProveedores = FabricaNegocio.getServicioProveedores();
        listaProv = new ArrayList();
        padre=(Mercaderias)parent;
        modificar=false;
        initComponents();
        cargarComboCategoria();
        cargarComboMarca();
        cargarComboProveedor();
        setLocationRelativeTo(parent);
        setVisible(true);

    }

      public AMMercaderia(javax.swing.JDialog parent, ArrayList<Object> datos, boolean modal) {
        super(parent, modal);
        mercaderias = new ControladorMercaderias(FabricaNegocio.getServicioMercaderias());
        serviciosCategorias = FabricaNegocio.getServicioCategorias();
        serviciosMarcas = FabricaNegocio.getServicioMarcas();
        serviciosProveedores = FabricaNegocio.getServicioProveedores();
        listaProv = new ArrayList();
        padre=(Mercaderias)parent;
        modificar=true;
        initComponents();
        cargarComboCategoria();
        cargarComboMarca();
        cargarComboProveedor();
        setLocationRelativeTo(parent);
        id=(Long)datos.get(0);
        textFieldNombre.setText((String) datos.get(1));
        comboMarca.setSelectedItem((String) datos.get(2));
        comboCategoria.setSelectedItem((String) datos.get(3));
        dateFecha.setDate((Date) datos.get(4));
        textFieldStock.setText(String.valueOf(datos.get(5)));
        checkBoxVence.setEnabled((Boolean) datos.get(6));
        textFieldPrecio.setText(String.valueOf(datos.get(7)));
        textFieldCompra.setText(String.valueOf(datos.get(8)));
        textFieldAlmacenamiento.setText(String.valueOf(datos.get(9)));
        setVisible(true);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        textFieldNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        textFieldStock = new javax.swing.JTextField();
        checkBoxVence = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        textFieldPrecio = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        textFieldCompra = new javax.swing.JTextField();
        textFieldAlmacenamiento = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        comboMarca = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();
        comboCategoria = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        comboProveedor = new javax.swing.JComboBox();
        dateFecha = new com.toedter.calendar.JDateChooser();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Agregar/Modificar Mercadería"));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setText("Nombre:");

        textFieldNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldNombreKeyTyped(evt);
            }
        });

        jLabel2.setText("Fecha vencimiento:");

        jLabel3.setText("Stock:");

        textFieldStock.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldStockKeyTyped(evt);
            }
        });

        checkBoxVence.setText("Vence");

        jLabel4.setText("$ de venta:");

        textFieldPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldPrecioKeyTyped(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel5.setText("$ de compra:");

        jLabel6.setText("$ de almacenamiento:");

        textFieldCompra.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldCompraKeyTyped(evt);
            }
        });

        textFieldAlmacenamiento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textFieldAlmacenamientoKeyTyped(evt);
            }
        });

        jLabel7.setText("Marca:");

        jButton4.setText("Guardar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel8.setText("Categoría:");

        jLabel9.setText("Proveedor:");

        jLabel10.setForeground(new java.awt.Color(255, 51, 0));
        jLabel10.setText("*");

        jLabel11.setForeground(new java.awt.Color(255, 51, 0));
        jLabel11.setText("*");

        jLabel12.setForeground(new java.awt.Color(255, 51, 0));
        jLabel12.setText("*");

        jLabel13.setForeground(new java.awt.Color(255, 51, 0));
        jLabel13.setText("*");

        jLabel14.setForeground(new java.awt.Color(255, 51, 0));
        jLabel14.setText("*");

        jLabel15.setForeground(new java.awt.Color(255, 51, 0));
        jLabel15.setText("*");

        jLabel16.setForeground(new java.awt.Color(255, 51, 0));
        jLabel16.setText("*");

        jLabel17.setForeground(new java.awt.Color(255, 51, 0));
        jLabel17.setText("*");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addGap(31, 31, 31))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(comboProveedor, javax.swing.GroupLayout.Alignment.TRAILING, 0, 278, Short.MAX_VALUE)
                            .addComponent(comboMarca, javax.swing.GroupLayout.Alignment.TRAILING, 0, 278, Short.MAX_VALUE)
                            .addComponent(textFieldNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                            .addComponent(comboCategoria, 0, 278, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)
                        .addComponent(textFieldStock, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)))
                .addGap(0, 0, 0)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 206, Short.MAX_VALUE)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel5))
                            .addComponent(jLabel4)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(50, 50, 50)
                                .addComponent(jLabel6)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textFieldAlmacenamiento)
                            .addComponent(textFieldCompra)
                            .addComponent(textFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel16)
                            .addComponent(jLabel15)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(checkBoxVence)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel2))
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dateFecha, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dateFecha, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(textFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(checkBoxVence)
                        .addComponent(jLabel2)
                        .addComponent(jLabel10)))
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel13))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel14))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)
                            .addComponent(jLabel11)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textFieldCompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textFieldAlmacenamiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel17))))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton4)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textFieldStock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel12))))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton2.setText("Agregar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(480, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(241, 241, 241))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void textFieldNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldNombreKeyTyped
        // TODO add your handling code here:
        Validaciones.ValidarSoloTexto(evt);
        Validaciones.LimitarCampo(evt, 40);
        Validaciones.ValidarCampoVacio(evt);
}//GEN-LAST:event_textFieldNombreKeyTyped

    private void textFieldStockKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldStockKeyTyped
        // TODO add your handling code here:
        Validaciones.ValidarCampoSoloNumerico(evt);
        Validaciones.LimitarCampo(evt, 4);
        Validaciones.ValidarCampoVacio(evt);
}//GEN-LAST:event_textFieldStockKeyTyped

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed

    private void textFieldAlmacenamientoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldAlmacenamientoKeyTyped
        // TODO add your handling code here:
        Validaciones.ValidarCampoSoloNumerico(evt);
        Validaciones.LimitarCampo(evt, 4);
}//GEN-LAST:event_textFieldAlmacenamientoKeyTyped

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        if ((textFieldNombre.getText().length() == 0)||(textFieldStock.getText().length() == 0)||(textFieldPrecio.getText().length() == 0)||(textFieldCompra.getText().length() == 0)||(textFieldAlmacenamiento.getText().length() == 0)||(comboMarca.getSelectedIndex()==-1)||(comboCategoria.getSelectedIndex()==-1)||(comboProveedor.getSelectedIndex()==-1)) {
           Validaciones.ValidarFormularioVacio(this);

        } else {
        ArrayList<Object> datos= new ArrayList();
        datos.add(textFieldNombre.getText());
        Date fecha = dateFecha.getDate();
        datos.add(fecha);
        datos.add(Integer.valueOf(textFieldStock.getText()));
        datos.add((Boolean) checkBoxVence.isSelected());
        datos.add(Double.valueOf(textFieldPrecio.getText()));


        //ControladorCategorias categorias = new ControladorCategorias(FabricaNegocio.getServicioCategorias());
        List<CategoriaProducto> listaCategorias = (List<CategoriaProducto>) serviciosCategorias.listar();
        CategoriaProducto categoria = new CategoriaProducto();
        categoria=listaCategorias.get(comboCategoria.getSelectedIndex());
        datos.add((CategoriaProducto) categoria);


        //ControladorProveedores proveedores = new ControladorProveedores(FabricaNegocio.getServicioProveedores());
        datos.add((ArrayList<Proveedor>)listaProv);


        MovimientoStock movimiento= new MovimientoStock();
        movimiento.setCantidad(Integer.valueOf(textFieldStock.getText()));
        Date hoy=new Date();
        movimiento.setFecha(hoy);
        movimiento.setTipo(TipoMovimiento.INGRESO);
        datos.add((MovimientoStock) movimiento);


       // ControladorMarcas marcas = new ControladorMarcas(FabricaNegocio.getServicioMarcas());
        List<MarcaProducto> listaMarcas = (List<MarcaProducto>) serviciosMarcas.listar();        
        MarcaProducto marca=new MarcaProducto();       
        marca=listaMarcas.get(comboMarca.getSelectedIndex());
        datos.add((MarcaProducto) marca);


        datos.add(Double.valueOf(textFieldCompra.getText()));
        datos.add(Double.valueOf(textFieldAlmacenamiento.getText()));
        if(modificar){
            datos.add(id);
            mercaderias.modificar(datos);
        } else
            mercaderias.nuevo(datos);
        mercaderias.actualizarTabla(padre);
        this.setVisible(false);
        JOptionPane.showMessageDialog(rootPane, "La operación se realizó con éxito");
        }
}//GEN-LAST:event_jButton4ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
         List<Proveedor> listaProveedores = (List<Proveedor>) serviciosProveedores.listar();
        Proveedor proveedor = new Proveedor();
        Boolean existe = false;
        if (comboProveedor.getSelectedIndex() == -1) {
           Validaciones.ValidarFormularioVacio(this);
        } else {
            proveedor = listaProveedores.get(comboProveedor.getSelectedIndex());

            for (Proveedor prov : listaProv) {
                if (prov.getId() == proveedor.getId()) {
                    existe = true;
                }
            }
            if (existe) {
               Validaciones.ValidarProveedorYaExiste(this);
            } else {
                listaProv.add(proveedor);
            }
        }


    }//GEN-LAST:event_jButton2ActionPerformed

    private void textFieldPrecioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldPrecioKeyTyped
        // TODO add your handling code here:
        Validaciones.LimitarCampo(evt, 4);
        Validaciones.ValidarCampoVacio(evt);
    }//GEN-LAST:event_textFieldPrecioKeyTyped

    private void textFieldCompraKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldCompraKeyTyped
        // TODO add your handling code here:
        Validaciones.LimitarCampo(evt, 4);
        Validaciones.ValidarCampoVacio(evt);
    }//GEN-LAST:event_textFieldCompraKeyTyped


      private void cargarComboCategoria(){
         List<CategoriaProducto> categorias = (List<CategoriaProducto>) serviciosCategorias.listar();
         for(CategoriaProducto categoria : categorias){
            comboCategoria.insertItemAt(categoria.getNombre(),categorias.indexOf(categoria));
         }
    }

    private void cargarComboMarca(){
         List<MarcaProducto> marcas = (List<MarcaProducto>) serviciosMarcas.listar();
         for(MarcaProducto marca : marcas){
            comboMarca.insertItemAt(marca.getNombre(),marcas.indexOf(marca));
         }
    }

    private void cargarComboProveedor(){
         List<Proveedor> proveedores = (List<Proveedor>) serviciosProveedores.listar();
         for(Proveedor proveedor : proveedores){
            comboProveedor.insertItemAt(proveedor.getNombre(),proveedores.indexOf(proveedor));
         }
    }

     void setControlador(ControladorMercaderias mercaderias) {
        this.mercaderias = mercaderias;
    }

    /**
    * @param args the command line arguments
    */
   /* public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AMMercaderia dialog = new AMMercaderia(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox checkBoxVence;
    private javax.swing.JComboBox comboCategoria;
    private javax.swing.JComboBox comboMarca;
    private javax.swing.JComboBox comboProveedor;
    private com.toedter.calendar.JDateChooser dateFecha;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField textFieldAlmacenamiento;
    private javax.swing.JTextField textFieldCompra;
    private javax.swing.JTextField textFieldNombre;
    private javax.swing.JTextField textFieldPrecio;
    private javax.swing.JTextField textFieldStock;
    // End of variables declaration//GEN-END:variables

}
